﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Handrise.CDCable.Mobile.Business;
using HandRise.MBHOP.Controls;

namespace Handrise.CDCable.Mobile.UI
{
    public partial class FrmTaskExecDetail : FrmBase
    {
        private Plan plan;

        private string linkIDs = "";

        private PatrolInfoService patrolInfoService = new PatrolInfoService();

        public FrmTaskExecDetail()
        {
            InitializeComponent();
            ttlbrhead.Text = "执行情况";

            ilstbcup.Images.Add(ResourceImage.s_修改01);
            ilstbcup.Images.Add(ResourceImage.s_照片01);
            ilstbcup.Images.Add(ResourceImage.s_录音01);
            ilstbcup.Images.Add(ResourceImage.s_返回01); 
            ilstbcdown.Images.Add(ResourceImage.s_修改02);
            ilstbcdown.Images.Add(ResourceImage.s_照片02);
            ilstbcdown.Images.Add(ResourceImage.s_录音02);
            ilstbcdown.Images.Add(ResourceImage.s_返回02);

        }

        private void FrmTaskExecDetail_Load(object sender, EventArgs e)
        {
            if (IsReturn)
                LoadCacheData();
            else
                LoadData();

            tbPlanTitle.Text = plan.Title;

            //获取所有计划下的巡视详情
            List<PatrolDetail> patrolDetails = patrolInfoService.GetAllPatrolDetailByPlan(plan.PlanID);

            string content = "";
            foreach (PatrolDetail patrolDetail in patrolDetails)
            {
                if (!string.IsNullOrEmpty(patrolDetail.PatrolItemName) && !string.IsNullOrEmpty(patrolDetail.DeviceName))
                {
                    content += patrolDetail.DeviceName + "(" + patrolDetail.PatrolItemName + ")异常；" + "\n\r";
                }

                linkIDs += ",'" + patrolDetail.PatrolDetailID + "'";
            }

            if (linkIDs != "")
                linkIDs = linkIDs.Remove(0, 1);

            if (content == "")
                content = "正常";

            lblContent.Text = content;
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            plan = (Plan)Parameter[0];


        }

        /// <summary>
        /// 加载缓存数据
        /// </summary>
        private void LoadCacheData()
        {
            plan = (Plan)Caches[0];
        }

        private void bcxunjian_OnButtonClick_1(object sender, int buttonIndex)
        {
            switch (buttonIndex)
            {
                case 0:  //修改
                    EditPlanDetail();
                    break;
                case 1: //照片
                    ShowPlanPicture();
                    break;
                case 2: //录音
                    ShowPlanRecord();
                    //FormManage.GotoNext("FrmRecordLst", null, null, false);
                    break;
                case 3: //返回
                       FormManage.GotoNext("FrmTaskDetail", null, null, true);
                       break;


            }

        }

        private void EditPlanDetail()
        {
            if (plan.State == "已完成")
            {
                mssdlgComfirm.ShowDialog(this, "当前计划已经完成，不能进行修改", DialogType.Confirm, FormManage.form_Deactivate);
                return;
            }
            FormManage.GotoNext("FrmPlanDeviceSelect", new object[] { plan }, new object[] { plan }, false);
        }

        private void ShowPlanPicture()
        {
            if (linkIDs == "")
            {
                mssdlgComfirm.ShowDialog(this, "当前计划没有照片信息", DialogType.Confirm, FormManage.form_Deactivate);

                return;
            }

            FormManage.GotoNext("FrmPictureList", new object[] { "FrmTaskExecDetail", linkIDs,plan }, new object[] { plan }, false);
        }

        private void ShowPlanRecord()
        {
            if (linkIDs == "")
            {
                mssdlgComfirm.ShowDialog(this, "当前计划没有录音信息", DialogType.Confirm, FormManage.form_Deactivate);
                return;
            }

            FormManage.GotoNext("FrmRecordLst", new object[] { "FrmTaskExecDetail", linkIDs,plan }, new object[] { plan }, false);
        }


    }
}